#include "Brick.h"
#include "OgreEntity.h"
#include "OgreRoot.h"
#include "OgreMaterialManager.h"
#include "OgreSubEntity.h"
#include "OgrePlane.h"
#include "OgreResourceGroupManager.h"
#include "OgreMeshManager.h"

CBrick::CBrick(void)
{
	mList = 0;
	mRow = 0;
	mAnimationState = NULL;
}

CBrick::~CBrick(void)
{
}

void CBrick::createScene( SceneManager* sceneMgr, SceneNode* parent, int i, int j )
{
	mPos = Vector3(31*i, 31*j, 0);
	mRow = i;
	mList = j;
	mEntity = sceneMgr->createEntity("xuanzhuan.mesh");
	mNode = parent->createChildSceneNode(mPos);
	mNode->attachObject(mEntity);
}

bool CBrick::frameStarted(const FrameEvent& evt)
{
	if (mAnimationState)
	{
		mAnimationState->addTime(evt.timeSinceLastFrame);
	}

	return true;
}

bool CBrick::frameEnded(const FrameEvent& evt)
{
	return true;
}

void CBrick::Right()
{
	if (mAnimationState)
	{
		mAnimationState->setEnabled(false);
	}
	mAnimationState = mEntity->getAnimationState("youzhuan");
	mAnimationState->setLoop(false);
	mAnimationState->setTimePosition(0.0f);
	mAnimationState->setEnabled(true);
}

bool CBrick::AnimationEnd()
{
	if (mAnimationState)
	{
		return mAnimationState->hasEnded();
	}
	return true;
}

void CBrick::createFrameListener( Root * root )
{
	root->addFrameListener(this);
}

void CBrick::Left()
{
	if (mAnimationState)
	{
		mAnimationState->setEnabled(false);
	}
	mAnimationState = mEntity->getAnimationState("zuozhuan");
	mAnimationState->setLoop(false);
	mAnimationState->setTimePosition(0.0f);
	mAnimationState->setEnabled(true);
}

